package com.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.common.dto.UserDTO;
import com.example.domain.User;
import com.example.service.UserService;
import com.example.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 惠普
 * @description 针对表【user】的数据库操作Service实现
 * @createDate 2022-09-27 15:05:30
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User>
		implements UserService {

	@Autowired
	private UserMapper userMapper;

	@Override
	public User getUserByTelephone(String telephone) {
		return userMapper.selectOne(new QueryWrapper<User>().eq("telephone", telephone));
	}

	@Override
	public List<User> getUserByCondition(UserDTO dto) {
		QueryWrapper<User> query = new QueryWrapper<>();
		query.eq(ObjectUtils.isNotNull(dto.getIdentity()), "identity", dto.getIdentity());
		query.eq(ObjectUtils.isNotNull(dto.getAuditRegistryState()), "audit_registry_state", dto.getAuditRegistryState());
		query.eq(ObjectUtils.isNotNull(dto.getEnableState()), "enable_state", dto.getEnableState());
		return baseMapper.selectList(query);
	}

	@Override
	public Page<User> getUserByConditionPage(UserDTO dto) {
		Page<User> page = new Page<>(dto.getCurrentPage(), dto.getPageSize());
		QueryWrapper<User> query = new QueryWrapper<>();
		query.eq(ObjectUtils.isNotNull(dto.getTelephone()), "telephone", dto.getTelephone());
		query.eq(ObjectUtils.isNotNull(dto.getIdentity()), "identity", dto.getIdentity());
		query.eq(ObjectUtils.isNotNull(dto.getRate()), "identity", dto.getRate());
		return baseMapper.selectPage(page, query);
	}
}




